﻿using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tools;
using 纺织贸易管理系统;

namespace 后整理管理系统.其他窗体
{
    public partial class 输入来货细码 : Sunny.UI.UIForm
    {
        public DataTable dt { get; set; } = new DataTable();
        public FormUseful useful { get; set; }
        public List<danjumingxitable> mingxilist { get; set; } = new List<danjumingxitable>();
        public 输入来货细码()
        {
            InitializeComponent();
        }

        private void 输入来货细码_Load(object sender, EventArgs e)
        {
            if (mingxilist.Count > 0)
            {
                foreach (var m in mingxilist.Where (x=>!string.IsNullOrEmpty( x.ganghao)).ToList ())
                {
                    if (!dt.Columns.Contains(m.ganghao))
                    {
                        dt.Columns.Add(m.ganghao);
                    }
                }
            }
            uiDataGridView1.DataSource = dt;
        }

        private void 输入来货细码_FormClosed(object sender, FormClosedEventArgs e)
        {
            uiDataGridView1.EndEdit();
        }

        private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void uiDataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            foreach(DataColumn col in dt.Columns)
            {
                decimal  totallength = 0;
                decimal totalroll = 0;
                foreach(DataRow row in dt.Rows )
                {
                   if(row[col].TryToDecmial(0)!=0)
                    {
                        totallength += row[col].TryToDecmial(0);
                        totalroll++;
                    }
                }
                var mingxi = mingxilist.FirstOrDefault(x => x.ganghao == col.ColumnName);
                if(mingxi!=null)
                {
                    mingxi.chengpingmishu = totallength;
                    mingxi.chengpingjuanshu = totalroll;
                }
            }
        }
    }
}
